package thread;

/**
 * Creared with IntelliJ IDEA.
 * Description:
 * User:yxd
 * Date:2022-03-26
 * Time:10:42
 */
public class Demo16 {
    public synchronized void method(){//锁普通方法相当于锁的是this

    }
    public synchronized static void method1(){//锁静态方法,锁的是类对象

    }
    public void method2(){
        synchronized (this){//锁代码块,需要明确指定,要锁哪个对象

        }
    }
    public void method3(){
        synchronized (Demo16.class){//通过反射锁类对象

        }
    }
}
